package com.victor.modular.system.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.victor.common.constant.Const;
import com.victor.common.constant.cache.Cache;
import com.victor.common.constant.cache.CacheKey;
import com.victor.common.constant.factory.ConstantFactory;
import com.victor.common.constant.state.Status;
import com.victor.common.exception.BizExceptionEnum;
import com.victor.common.exception.ValidationException;
import com.victor.common.persistence.dao.AudienceCodeMapper;
import com.victor.common.persistence.dao.AudienceMapper;
import com.victor.common.persistence.model.Audience;
import com.victor.common.persistence.model.AudienceCode;
import com.victor.config.properties.VictorProperties;
import com.victor.core.cache.CacheKit;
import com.victor.core.shiro.ShiroKit;
import com.victor.core.util.CommUtils;
import com.victor.core.util.ExcelUtil;
import com.victor.core.util.ToolUtil;
import com.victor.core.util.UploadFile;
import com.victor.modular.system.dao.AudienceDao;
import com.victor.modular.system.service.BaseService;
import com.victor.modular.system.service.IAudienceCodeService;
import com.victor.modular.system.service.IAudienceService;
import com.victor.modular.system.transfer.AudienceCodeDto;
import com.victor.modular.system.transfer.AudienceDto;
import com.victor.modular.system.transfer.AudienceImport;
import com.victor.modular.system.transfer.FileDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.util.*;

@Service
public class AudienceCodeServiceImpl extends BaseService implements IAudienceCodeService {
    @Autowired
    private AudienceCodeMapper audienceCodeMapper;
    @Autowired
    private AudienceDao audienceDao;
    /*模板*/
    @Resource
    protected VictorProperties victorProperties;
    @Override
    public void updateAudienceCode(AudienceCodeDto audienceCodeDto) throws Exception {
        AudienceCode audienceCode = new AudienceCode();
        audienceCode.setUpdatetime(new Date());
        audienceCode.setUpdateUserId(ShiroKit.getUser().getId());
        BeanUtils.copyProperties(audienceCodeDto,audienceCode);
        audienceCodeMapper.updateById(audienceCode);
        clearAllCache();

    }

    @Override
    public void addAudienceCode(AudienceCodeDto audienceCodeDto) throws Exception {
        AudienceCode audienceCode = new AudienceCode();
        audienceCode.setCreatetime(new Date());
        audienceCode.setCreateUserId(ShiroKit.getUser().getId());
        BeanUtils.copyProperties(audienceCodeDto,audienceCode);
        audienceCodeMapper.insert(audienceCode);
        clearAllCache();
    }

    @Override
    public void deleteAudienceCode(Integer id) throws Exception{
        AudienceCode audienceCode = audienceCodeMapper.selectById(id);
        audienceCodeMapper.deleteById(audienceCode);
        CacheKit.removeAll(Cache.CONSTANT);
        clearAllCache();
    }


}
